<?php

/**
 * This is the model class for table "category".
 *
 * The followings are the available columns in table 'category':
 * @property integer $id
 * @property string $name
 * @property string $description
 * @property integer $is_activity
 * @property integer $is_news
 * @property integer $is_document
 * @property integer $is_deleted
 */
class Category extends CActiveRecord
{
    private $type;

    /**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Category the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'category';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id, name, is_activity, is_news, is_document, is_deleted', 'required'),
			array('id, is_activity, is_news, is_document, is_deleted', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>50),
			array('description', 'length', 'max'=>400),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, description, is_activity, is_news, is_document, is_deleted', 'safe', 'on'=>'search'),
                        array('type','safe'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'description' => 'Description',
			'is_activity' => 'Is Activity',
			'is_news' => 'Is News',
			'is_document' => 'Is Document',
			'is_deleted' => 'Is Deleted',
                        'type'=>'Type',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('is_activity',$this->is_activity);
		$criteria->compare('is_news',$this->is_news);
		$criteria->compare('is_document',$this->is_document);
		$criteria->compare('is_deleted',$this->is_deleted);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
        public function getType()
        {
            $item = Category::model()->findByPk($this->id);
//            $item = Category::model()->findByPk(1);
            if($item->is_activity)
            {
                return 'Activity';
            }
            else if($item->is_news)
            {
                return 'News';
            }
            else if($item->is_document)
            {
                return 'Document';
            }
            return '';
        }
        public function setType($value)
        {
            $this->type = $value;
        }
}